FROM ray-dev:2.34.0-py311-cu121
LABEL maintainer="txtech"

# set username & uid inside docker
USER root
ARG UNAME=root
ENV WORKDIR="/work"

ARG TORCH_VERSION=2.3.1
ARG TORCHVISION_VERSION=0.18.1
ARG TORCHAUDIO_VERSION=2.3.1
ENV FORCE_CUDA="1"

RUN mkdir -p /home/ray/.cache/modelscope/hub
#COPY /data/.cache/modelscope/hub /home/ray/.cache/modelscope/hub

# set work directory

ENV DEBIAN_FRONTEND=noninteractive

### change the system source for installing libs
ARG USE_SRC_INSIDE=true
RUN if [ ${USE_SRC_INSIDE} == true ] ; \
    then \
        sed -i s/archive.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list ; \
        sed -i s/security.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list ; \
        echo "Use aliyun source for installing libs" ; \
    else \
        echo "Keep the download source unchanged" ; \
    fi

### change the pip source for installing packages
RUN if [ ${USE_SRC_INSIDE} == true ] ; \
    then \
        pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple; \
        echo "pip using tsinghua source" ; \
    else \
        echo "Keep pip the download source unchanged" ; \
    fi

RUN apt-get update && apt-get install -y vim cron && apt-get clean
#RUN (crontab -l;echo "55 23 * * * /home/ray/anaconda3/bin/serve shutdown -y") | crontab
#RUN (crontab -l;echo "0 8 * * * cd /work/server/search-server && /home/ray/anaconda3/bin/serve run configs/config.yaml") | crontab
#RUN pip install "$WORKDIR/packages/onnxruntime_gpu-1.18.1-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl" --no-cache-dir
RUN pip3 install --no-cache-dir pymongo langchain vllm accelerate
RUN pip3 install -U funasr==1.1.11
#RUN pip install -r requirments.txt --no-cache-dir --upgrade
#RUN conda install -c conda-forge 'ffmpeg<7' -y && \
#    conda clean -ya
WORKDIR ${WORKDIR}
# copy app & scripts to src & exclude those in dockerignore
#COPY audio_asr "$WORKDIR/audio_asr"
#COPY audio_embedding "$WORKDIR/audio_embedding"
#COPY auto_cut "$WORKDIR/auto_cut"
#COPY backtracking "$WORKDIR/backtracking"
#COPY static "$WORKDIR/static"
#COPY main.py "$WORKDIR/main.py"
COPY requirments.txt "$WORKDIR/requirments.txt"
COPY packages "$WORKDIR/packages"
COPY job "$WORKDIR/job"
COPY server "$WORKDIR/server"

# change file ownership to docker user:usergroup
RUN #sudo chown $UNAME:$UNAME $WORKDIR

RUN rm -rf "$WORKDIR/packages"

ENTRYPOINT  service cron start && \
            ray start --head --dashboard-host 0.0.0.0 && \
            pwd && cd job &&\
            uvicorn main:app --host 0.0.0.0 --port 8002 --reload
